//
//  ScreenRasterScrollView.m
//  Screen_Raster2
//
//  Created by Tianzhou on 08-11-12.
//  Copyright 2008 Tianzhou Software Inc.. All rights reserved.
// 
//   Licensed under the Apache License, Version 2.0 (the "License"); you may not
//   use this file except in compliance with the License.  You may obtain a copy
//   of the License at
//  
//   http://www.apache.org/licenses/LICENSE-2.0
// 
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
//   WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
//   License for the specific language governing permissions and limitations under
//   the License.
//

#import "ScreenRasterScrollView.h"
#import "ScreenRasterTransparentView.h"

@interface ScreenRasterScrollView(private_method)
// The visible screen excludes dock and menubar area;
- (NSPoint)convertScreenPointToVisibleScreenPoint:(NSPoint)theScreenPoint;
@end

@implementation ScreenRasterScrollView(private_method)

- (NSPoint)convertScreenPointToVisibleScreenPoint:(NSPoint)theScreenPoint
{
	NSRect theFrame = [[NSScreen mainScreen] frame];
	NSRect theVisibleFrame = [[NSScreen mainScreen] visibleFrame];
	NSPoint translateVector = NSMakePoint(theFrame.origin.x - theVisibleFrame.origin.x
	                                      ,theFrame.origin.y - theVisibleFrame.origin.y);
	return NSMakePoint(theScreenPoint.x - translateVector.x, theScreenPoint.y - translateVector.y);
}

@end

@implementation ScreenRasterScrollView

- (id)initWithFrame:(NSRect)frameRect
{
	if( (self = [super initWithFrame:frameRect]) != nil )
	{
		NSPoint rulerOrigin = [self convertScreenPointToVisibleScreenPoint:NSMakePoint(0,0)];
		NSRulerView *theHorzRuler = [[NSRulerView alloc] init];
		[theHorzRuler setReservedThicknessForMarkers:1.0];
		[theHorzRuler setReservedThicknessForAccessoryView:0.0];
		[theHorzRuler setMeasurementUnits:@"Points"];
		[self setHorizontalRulerView:theHorzRuler];
		[theHorzRuler release];
		
		NSRulerView *theVertRuler = [[NSRulerView alloc] init];
		[theVertRuler setReservedThicknessForMarkers:1.0];
		[theVertRuler setReservedThicknessForAccessoryView:0.0];
		[theVertRuler setMeasurementUnits:@"Points"];
		[self setVerticalRulerView:theVertRuler];
		[theVertRuler release];
		
		[[self horizontalRulerView] setOriginOffset:-rulerOrigin.x - [[self verticalRulerView] ruleThickness]];
		[[self verticalRulerView] setOriginOffset:-rulerOrigin.y - [[self horizontalRulerView] ruleThickness]];
		
		[self setRulersVisible:YES];
		
		ScreenRasterTransparentView *theDocumentView = [[ScreenRasterTransparentView alloc] initWithFrame:frameRect];
		[self setDocumentView:theDocumentView];
		[theDocumentView release];
		
	}
	return self;
}


- (BOOL)isFlipped
{
	return NO;
}

@end
